<template>
  <div>
    <el-dialog
      title="5555"
      :visible.sync="dialogVisible"
      width="30%"
      @closed="handleClose"
    >
      <span>头部消息</span>
      <el-form
        ref="myForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
        :rules="rules"
      >
        <el-form-item label="审批人" prop="user">
          <el-input
            v-model="formInline.user"
            placeholder="审批人"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item label="审批人Two" prop="userTwo">
          <el-input
            v-model="formInline.userTwo"
            placeholder="审批人Two"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item label="活动区域">
          <el-select
            v-model="formInline.region"
            placeholder="活动区域"
            clearable
            size="small"
          >
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">定</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >点开</el-button
        >
      </span>
    </el-dialog>
    <el-button size="small" @click="handleOpenDialog">点我赋值并打开</el-button>
    <el-button size="small" type="success" @click="handleOpen"
      >点我打开</el-button
    >
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      formInline: {
        user: "",
        region: "",
        userTwo:"",
      },
      rules: {
        user: [
          {
            required: true,
            message: "请输入活动名称",
            trigger: "blur||change",
          },
          ,
        ],
      },
    };
  },
  methods: {
    // 单纯打开弹窗
    handleOpen() {
      this.dialogVisible = true;
    },
    // 打开弹窗，并赋值
    handleOpenDialog() {
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.formInline = {
          user: "22",
          region: "beijing",
          userTwo:"33"
        };
      });
    },
    handleClose() {
      console.log(123);
      this.$nextTick(() => {
        this.$refs.myForm.resetFields();
      });
    },
  },
};
</script>
